﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace TellagoInc.VsTagExplorer.TagSelector
{
    public partial class TagsSelector : Form, ITagSelector
    {
        public bool Selected
        {
            get { return DialogResult == DialogResult.OK; }
        }

        public TagsSelector()
        {
            InitializeComponent();
        }

        #region ITagSelector Members

        public IEnumerable<string> Select(IEnumerable<string> candidates)
        {
            txtTags.Text = string.Join(" ", candidates);
            txtTags.Focus();
            return ShowDialog() == DialogResult.OK
                       ? txtTags.Text.Split(new[] {' '}).Select(t => t.Trim()).Where(t => !string.IsNullOrEmpty(t))
                       : new string[0];
        }

        #endregion

        private void OkButtonClick(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            Close();
        }

        private void CancelButtonClick(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }


    }
}